package com.car.intercept;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;

import com.car.action.admin.LoginController;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.utils.APIJSON;
import com.utils.JwtToken;

public class ApiCommonInterceptor implements Interceptor {

	private static Logger logger = Logger.getLogger(ApiCommonInterceptor.class);
	
    public void intercept(Invocation inv) {
        Controller controller = inv.getController();
        HttpServletRequest request = controller.getRequest();
        try {
        	String token = request.getParameter("token");
			Long user_id = JwtToken.getAppUID(token);
			if (user_id > 0L) {
				inv.invoke();
			} else {
				controller.renderText(APIJSON.result(-1));
				return;
			} 
			
		} catch (Exception e) {
			controller.renderText(APIJSON.result(-1));
			return;
		}
        
        
    }

}
